package com.pg_chat.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pg_chat.config.MsgConfig;


/**
 * JSON 工具类，支持数据转换
 */
public class JsonUtil {

    public static String convertObj2JSON(Object root){
        String result = "";
        try{
            result = JSON.toJSONString(root);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

//    public static<T> T convertJSON2Obj(String json, Class<T> clazz){
//        return new ;
//    }

    public static JSONObject resultMsg(MsgConfig config){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",config.getCode());
        jsonObject.put("message",config.getMessage());
        jsonObject.put("data",config.getDate());

        return jsonObject;
    }

    public static String resultMsgStr(MsgConfig config){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",config.getCode());
        jsonObject.put("message",config.getMessage());
        jsonObject.put("data",config.getDate());

        return jsonObject.toJSONString();
    }
}
